package com.css.fxfzypg.modules.earthquakedisasterloss.controller;

import com.alibaba.fastjson.JSONObject;
import com.css.fxfzypg.base.response.RestResponse;
import com.css.fxfzypg.logInfo.SysLog;
import com.css.fxfzypg.modules.earthquakedisasterloss.service.CountEqIntensityService;
import com.css.fxfzypg.modules.earthquakedisasterloss.service.CountMaterialService;
import com.css.fxfzypg.modules.hypergraph.service.HypergraphService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Description: fxfzypg
 * @Author: lhl
 * @CreateDate: 2022/10/13 9:48
 */
@RestController
@Slf4j
@RequestMapping("/count")
public class CountEqIntensityController {

    @Resource
    CountEqIntensityService countEqIntensityService;
    @Resource
    HypergraphService hypergraphService;

    @SysLog("计算地震影响场")
    @PostMapping("/countEqIntensity")
    public RestResponse countEqIntensity(@RequestParam String taskId, @RequestParam String modelId,@RequestParam String range){
        RestResponse restResponse = null;
        try {
            restResponse = countEqIntensityService.countEqIntensity(taskId, modelId,range);
            //刷新指定超图工作空间数据源数据集
            boolean bool = hypergraphService.getWorkspaceReload("setting_seismic_influenceflied");

            if (restResponse.getCode()==200) {
                restResponse = RestResponse.succeed("计算地震影响场生成成功！");
            }
        }catch (Exception e){
            e.printStackTrace();
            restResponse = RestResponse.fail(503,"计算地震影响场生成失败！");
        }
        return restResponse;
    }

    @SysLog("根据任务id 获取影响场的计算方式")
    @GetMapping("/getRangeByTaskId/{taskId}")
    public RestResponse getRangeByTaskId(@PathVariable String taskId){
        RestResponse restResponse = null;
        try {
            restResponse = countEqIntensityService.getRangeByTaskId(taskId);
        }catch (Exception e){
            e.printStackTrace();
            restResponse = RestResponse.fail(503,"根据任务id获取影响场的计算方式失败！");
        }
        return restResponse;
    }
    @SysLog("根据任务id 删除影响场相关计算数据")
    @GetMapping("/deleteDateByTaskId/{taskId}")
    public RestResponse deleteDateByTaskId(@PathVariable String taskId){
        RestResponse restResponse = null;
        try {
            restResponse = countEqIntensityService.deleteDateByTaskId(taskId);
        }catch (Exception e){
            e.printStackTrace();
            restResponse = RestResponse.fail(503,"删除影响场相关计算数据失败！");
        }
        return restResponse;
    }
}
